package busserver;

import java.util.ArrayList;
import java.util.List;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.ObjectRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.representation.Variant;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class AllStationsResource extends ServerResource {
    @Get()
    public ObjectRepresentation<BusLib.ObjectList> getData() {
        try {
            // Pentru a obtine textul id-urilor
            //String idStr = (String)getRequest().getAttributes().get("NUME_ID");
            // apoi trebuie convertit in int

            // Obtine lista cu toate statiile.
            DataProvider provider = BusApplication.getProvider();
            List<BusLib.StationInfo> stations = provider.GetAllStations();

            BusLib.ObjectList list = new BusLib.ObjectList(stations);
            return new ObjectRepresentation<BusLib.ObjectList>(list);
        }
        catch(Exception e) {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return null;
        }
    }
}
